# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=groff
pkgver=1.22.3
pkgrel=1
pkgdesc="GNU troff text-formatting system"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/groff/groff.html"
license=('GPL')
groups=('base-devel')
depends=('perl' 'gcc-libs')
makedepends=()
optdepends=()
source=(ftp://ftp.gnu.org/gnu/groff/groff-$pkgver.tar.gz{,.sig}
        site.tmac
        groff-1.22.2-msys2.patch
        0001-fix-mom-pdf-symlink.patch)
options=('!docs' '!emptydirs')
install=groff.install
md5sums=('cc825fa64bc7306a885f2fb2268d3ec5'
         'SKIP'
         'a1fedafd7863b37968d32ad9ae1d8c13'
         'cd30f724b1f2e7af13abd201b14568d0'
         '44556be01a856040f850f0ea5fcd0d0e')

prepare() {
  cd $srcdir/$pkgname-$pkgver

  patch -p2 -i $srcdir/0001-fix-mom-pdf-symlink.patch
  patch -p1 -i $srcdir/groff-1.22.2-msys2.patch

  autoreconf -fvi -I m4
}

build() {
  cd $srcdir/$pkgname-$pkgver
  ./configure --prefix=/usr
  make
}

check() {
  cd $srcdir/$pkgname-$pkgver
  make check
}

package() {
  cd $srcdir/$pkgname-$pkgver
  make DESTDIR=$pkgdir install

  rm -f $pkgdir/usr/lib/charset.alias

  # FS33760 - TERMCAP variables not followed
  # TODO: everyone is doing this - find out why upstream does not...
  cat $srcdir/site.tmac >> \
    $pkgdir/usr/share/groff/site-tmac/man.local
  cat $srcdir/site.tmac >> \
    $pkgdir/usr/share/groff/site-tmac/mdoc.local
}
